<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="商家" prop="sellerId">
      <el-input v-model="dataForm.sellerId" placeholder="商家"></el-input>
    </el-form-item>
    <el-form-item label="用户ID" prop="userId">
      <el-input v-model="dataForm.userId" placeholder="用户ID"></el-input>
    </el-form-item>
    <el-form-item label="参数" prop="parameter">
      <el-input v-model="dataForm.parameter" placeholder="参数"></el-input>
    </el-form-item>
    <el-form-item label="状态(0待审1通过2驳回)" prop="state">
      <el-input v-model="dataForm.state" placeholder="状态(0待审1通过2驳回)"></el-input>
    </el-form-item>
    <el-form-item label="类型(0商家信息1商家实名信息2商家信息图片3商家房型图片)" prop="type">
      <el-input v-model="dataForm.type" placeholder="类型(0商家信息1商家实名信息2商家信息图片3商家房型图片)"></el-input>
    </el-form-item>
    <el-form-item label="实体类" prop="entityBean">
      <el-input v-model="dataForm.entityBean" placeholder="实体类"></el-input>
    </el-form-item>
    <el-form-item label="反射service" prop="springBean">
      <el-input v-model="dataForm.springBean" placeholder="反射service"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="creatTime">
      <el-input v-model="dataForm.creatTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
    </el-form-item>
    <el-form-item label="操作员" prop="operator">
      <el-input v-model="dataForm.operator" placeholder="操作员"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          sellerId: '',
          userId: '',
          parameter: '',
          state: '',
          type: '',
          entityBean: '',
          springBean: '',
          creatTime: '',
          updateTime: '',
          operator: ''
        },
        dataRule: {
          sellerId: [
            { required: true, message: '商家不能为空', trigger: 'blur' }
          ],
          userId: [
            { required: true, message: '用户ID不能为空', trigger: 'blur' }
          ],
          parameter: [
            { required: true, message: '参数不能为空', trigger: 'blur' }
          ],
          state: [
            { required: true, message: '状态(0待审1通过2驳回)不能为空', trigger: 'blur' }
          ],
          type: [
            { required: true, message: '类型(0商家信息1商家实名信息2商家信息图片3商家房型图片)不能为空', trigger: 'blur' }
          ],
          entityBean: [
            { required: true, message: '实体类不能为空', trigger: 'blur' }
          ],
          springBean: [
            { required: true, message: '反射service不能为空', trigger: 'blur' }
          ],
          creatTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ],
          operator: [
            { required: true, message: '操作员不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/seller/tsellerhistoricaldata/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.sellerId = data.tSellerHistoricalData.sellerId
                this.dataForm.userId = data.tSellerHistoricalData.userId
                this.dataForm.parameter = data.tSellerHistoricalData.parameter
                this.dataForm.state = data.tSellerHistoricalData.state
                this.dataForm.type = data.tSellerHistoricalData.type
                this.dataForm.entityBean = data.tSellerHistoricalData.entityBean
                this.dataForm.springBean = data.tSellerHistoricalData.springBean
                this.dataForm.creatTime = data.tSellerHistoricalData.creatTime
                this.dataForm.updateTime = data.tSellerHistoricalData.updateTime
                this.dataForm.operator = data.tSellerHistoricalData.operator
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/seller/tsellerhistoricaldata/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'sellerId': this.dataForm.sellerId,
                'userId': this.dataForm.userId,
                'parameter': this.dataForm.parameter,
                'state': this.dataForm.state,
                'type': this.dataForm.type,
                'entityBean': this.dataForm.entityBean,
                'springBean': this.dataForm.springBean,
                'creatTime': this.dataForm.creatTime,
                'updateTime': this.dataForm.updateTime,
                'operator': this.dataForm.operator
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
